package controllers

import (
	"net/http"
	"xmgl/models"

	"github.com/astaxie/beego"
)

type MainController struct {
	beego.Controller
}

func (this *MainController) Get() {
	var (
		menu models.Menu_gl
		user models.Sut_user
	)

	if this.GetSession("USER") == nil {
		//没有取到session值，页面跳转
		http.Redirect(this.Ctx.ResponseWriter, this.Ctx.Request, "/login", http.StatusFound)
	}

	tmp, ok := this.GetSession("USER").(models.Sut_user) //注意类型断言
	if ok {
		user = tmp
	}
	//log.Println("default.go MainController Get() 从session中取出用户姓名：", user.User_name) //good

	this.Data["WEBSITE"] = "首页"
	this.Data["MENU_LEFT"] = menu.Get_left_menu()
	this.Data["MENU_RIGHT"] = menu.Get_right_menu()
	this.Data["USER_NAME"] = user.User_name

	this.Layout = "layout.html"
	this.TplName = "index.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHeader"] = "html_header.html"
	//this.LayoutSections["Menu_gl"] = "menu_gl.html"
}
